import request from '@/utils/request'
import {encrypt} from '@/utils/rsaEncrypt'

export function add(data) {
  return request({
    url: 'api/users',
    method: 'post',
    data
  })
}

export function del(id) {
  return request({
    url: 'api/users/' + id,
    method: 'delete'
  })
}

export function edit(data) {
  return request({
    url: 'api/users',
    method: 'put',
    data
  })
}

export function suspension(data) {
  return request({
    url: 'api/users/suspend',
    method: 'post',
    data
  })
}

export function reset(username) {
  const params = {
    username: username
  }
  return request({
    url: 'api/users/reset',
    method: 'put',
    params
  })
}

export function updatePass(user) {
  const data = {
    oldPass: encrypt(user.oldPass),
    newPass: encrypt(user.newPass)
  }
  return request({
    url: 'api/users/updatePass/',
    method: 'post',
    data
  })
}

export function updateUserPass(user) {
  const data = {
    newPass: encrypt(user.newPass),
    userName:user.userName
  }
  return request({
    url: 'api/users/updateUserPass',
    method: 'post',
    data
  })
}

export function updateEmail(code, data) {
  return request({
    url: 'api/users/updateEmail/' + code,
    method: 'post',
    data
  })
}

export function findDeptUser(deptId, roleFlag) {
  const params = {
    deptId: deptId,
    roleFlag: roleFlag
  }
  return request({
    url: 'api/users/transfer',
    method: 'get',
    params
  })
}

export function updateAvatarV2(params) {
  return request({
    url: 'api/users/updateAvatarV2',
    method: 'get',
    params
  })
}

